<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let params = {
            page: 1,
            size: 10
        }

        // 方法一
        /*
            var str = ""
            for (var attr in params) {
                // console.log(attr + "=" + params[attr]);
                str += attr + "=" + params[attr] + "&"
            }
            console.log(str.slice(0, -1));  // page=1&size=10
        */

        // 方法二
        console.log(Object.keys(params)); // ["page", "size"]
        var str = ""
        Object.keys(params).forEach(key => {
            console.log(key); //page  || size
            str += key + "=" + params[key] + "&"
        })
        console.log(str.lastIndexOf("&")); //最后一个&符号的索引
        console.log(str.substr(0, str.lastIndexOf("&"))); //page=1&size=10
    </script>
</body>

</html>